package com.max.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionUtils {

    //驱动类路径
    private final static String driver = "com.mysql.cj.jdbc.Driver";
    //数据库地址  // http://ip:prod
    private final static String url = "jdbc:mysql://127.0.0.1:3306/meeting";
    //登录用户名
    private final static String username = "root";
    //登录密码
    private final static String password = "ludan";

    private static Connection connection;

    public static Connection getConnection() {
        if (connection != null) {
            return connection;
        }
        try {
            //加载驱动类
            Class.forName(driver);
            //通过驱动管理器获取数据库连接
            connection = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException(e);
        }
        return connection;
    }


}
